package com.hyy.taobao.controller;

import com.hyy.taobao.api.IMyCartService;
import com.hyy.taobao.api.entity.MyCart;
import com.hyy.taobao.api.entity.User;
import com.hyy.taobao.service.MyCartServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Set;

@WebServlet("/selectGoods")
public class MyCartSelectGoodsServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;utf-8");
        HttpSession session = req.getSession();
        User myUser = (User) session.getAttribute("myUser");
        String userName = myUser.getUserName();
        String s = req.getParameter("judgement");
        int judgement = Integer.parseInt(s);
        if (judgement == 0) {
            if (!"".equals(userName)) {
                MyCart myCart = new MyCart(userName);
                IMyCartService iMyCartService = new MyCartServiceImpl();
                Set<MyCart> myCartSet = iMyCartService.myCartSelectGoods(myCart);
                req.setAttribute("myCartSet", myCartSet);
                req.getRequestDispatcher("myCart.jsp").forward(req, resp);
            } else {
                req.setAttribute("msg", "查看失败！");
                req.getRequestDispatcher("myCart.jsp").forward(req, resp);
            }
        }
    }
}
